package learning.algorithm.complexity;

import learning.algorithm.utils.TimeUtil;

public class Main {
    public static void main(String[] args) {

//        System.out.println(123);
//        System.out.println(fib2(64));
        int n = 46;
        TimeUtil.test("fib1", () ->
                System.out.println(fib(n))
        );
        TimeUtil.test("fib2", () ->
                System.out.println(fib2(n))
        );

    }

    public static long fib2(int n) {
        if (n <= 1) {
            return n;
        }
        long first = 0;
        long second = 1;
        for (int i = 0; i < n - 1; i++) {
            long sum = first + second;
            first = second;
            second = sum;
        }
        return second;
    }

    public static long fib(int n) {
        if (n <= 1) {
            return n;
        }

        return fib(n - 1) + fib(n - 2);
    }
}
